package com.aier.admin.action;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.aier.admin.common.AdminExcelUtil;
import com.aier.admin.common.AdminUtil;
import com.aier.common.common.Constant;

@Scope("prototype")
@Component("adminICCreateAction")
public class AdminICCreateAction extends AdminBaseAction {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private ByteArrayInputStream inputExcel;
    private String filename;
    private String[] sign;
    private int sn;
    private int en;

    @Override
    public String execute() {
        return SUCCESS;
    }

    public String down() {
        int sleng = Constant.num_6;
        if (en >= Constant.num_100000) {
            sleng = String.valueOf(en).length();
        }
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
            AdminExcelUtil.createExcel(sign, sn, en, sleng).write(out);
        } catch (IOException e) {
            return null;
        }
        inputExcel = new ByteArrayInputStream(out.toByteArray());
        filename="";
        for (int i = 0; i < sign.length; i++) {
            filename += sign[i] + "_";
        }
        filename += AdminUtil.leftPading(String.valueOf(sn), "0", sleng) + "_"
                + AdminUtil.leftPading(String.valueOf(en), "0", sleng) + ".xls";
        return SUCCESS;
    }

    public ByteArrayInputStream getInputExcel() {
        return inputExcel;
    }

    public String getFilename() {
        return filename;
    }

    public void setSign(String[] sign) {
        this.sign = sign;
    }

    public void setSn(int sn) {
        this.sn = sn;
    }

    public void setEn(int en) {
        this.en = en;
    }

}
